package com.ems.controller;

import com.ems.dao.QuestionDao;
import com.ems.entity.Question;
import com.ems.exception.Result;
import com.ems.exception.ResultCode;
import com.ems.service.TeacherService;
import com.ems.service.impl.TeacherServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @Autowired
    QuestionDao questionDao;

    @Autowired
    TeacherService teacherService;

    @RequestMapping(value = "/test/put")
    public String put(Question question)
    {
       questionDao.insert(question);
       return "index";
    }

    @RequestMapping(value = "/test/t1",method = RequestMethod.GET)
    public Object test(Integer eid){
        if (eid != null)
        {
            TeacherServiceImpl.RES studentPaper = (TeacherServiceImpl.RES) teacherService.getStudentPaper(eid);
            if (studentPaper.isIsnull()) return Result.state(ResultCode.HAS_FINISH);
            else if (studentPaper.isException()) return Result.no();
            return Result.ok().data(studentPaper.getData());

        }
        return Result.state(ResultCode.NULLPOINTER);
    }
}
